﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xinkui.WebModel.BasicControl;
using Xinkui.DataAccess.AutoGenerator;
using Xinkui.Common;
using CommonFramework.Utility;
using Xinkui.WebModel.Model;
using Xinkui.WebModel.Cache;
using Xinkui.WebModel;
using Xinkui.Common.FileAction;
using Xinkui.Common.Enum;
using Xinkui.WebModel.Helper;

public partial class UserControl_ShowRoom_UC_ProductDetail : ShowRoomControl {

    protected string Description { get; set; }

    protected int ProductId { get; set; }

    protected string ProductName { get; set; }

    protected string ImagePath { get; set; }
    protected void Page_Load(object sender, EventArgs e) {
        ImagePath = UIHelper.BindingImage("", ESourceType.FromProductImage, ImageSizeEnum.S200);
        var productDetail = Singleton<ProductInfoDataAccess>.Instance.ProductInfo_View(WebHelper.GetQueryStringValue<int>("pro", 0));
        List<PropertyItem> properties = new List<PropertyItem>();
        if (productDetail != null) {
            Description = productDetail.ProductDescription;
            ProductId = productDetail.ProductID;
            ProductName = productDetail.ProductName;

            properties.Add(new PropertyItem { Title = "Application", Value = productDetail.Application, OrderBy = 1 });

            //properties.Add(new PropertyItem { Title = "Key Products", Value = productDetail.KeyProducts, OrderBy = 2 });

            properties.Add(new PropertyItem { Title = "OEM No/Model", Value = productDetail.OEMNO, OrderBy = 3 });

            properties.Add(new PropertyItem { Title = "Place Of Region", Value = productDetail.PlaceOfOrigin, OrderBy = 4 });

            if (!string.IsNullOrEmpty(productDetail.CertificateIDS)) {
                string[] ids = productDetail.CertificateIDS.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < ids.Length; i++) {
                    var cert = Singleton<CompanyCertificateDataAccess>.Instance.CompanyCertificate_View(CommonFramework.Utility.ConvertHelper.ToType<int>(ids[i]));
                    if (cert != null) {
                        ids[i] = cert.CertName;
                    }
                    else {
                        ids[i] = string.Empty;
                    }
                }
                properties.Add(new PropertyItem { Title = "Quality Certificate", Value = string.Join(",", ids.Where(u => !string.IsNullOrEmpty(u))), OrderBy = 5 });
            }
            //properties.Add(new PropertyItem { Title = "Place Of Region", Value = productDetail., OrderBy = 4 });

        }
        rptDataProperies.DataSource = properties.Where(u => !string.IsNullOrEmpty(u.Value)).OrderBy(u => u.OrderBy);
        rptDataProperies.DataBind();


        ImagePath = UIHelper.BindingImage(productDetail.PicImgs, Xinkui.Common.Enum.ESourceType.FromProductImage, ImageSizeEnum.S200);
        
    }
}